package com.mxdx.edu.service.impl;

import com.mxdx.edu.dao.HwLibraryDao;
import com.mxdx.edu.model.ExamStudentRecord;
import com.mxdx.edu.model.HwStudentRecord;
import com.mxdx.edu.service.IHwLibraryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

@Service
public class HwLibraryServiceImpl implements IHwLibraryService {

    @Resource
    private HwLibraryDao hwLibraryDao;

    @Override
    public Map<String, Object> findHwTitleByMap(Map<String, Object> param){

        return hwLibraryDao.findHwTitleByMap(param);
    }

    //根据课程id获取考试信息
    @Override
    public Map<String, Object> findHwTitleByCourseId(String courseId){

        Map<String, Object> param = new HashMap<>();
        param.put("courseId", courseId);

        Map<String, Object> hwTitleMap = hwLibraryDao.findHwTitleByMap(param);

        return hwTitleMap;
    }

    //根据考试id获取考试大题信息
    @Override
    public List<Map<String,Object>> findHwSubjectByHwId(String hwId){

        Map<String, Object> param = new HashMap<>();
        param.put("hwId", hwId);

        List<Map<String, Object>>  hwSubjectListMap = hwLibraryDao.findHwSubjectByMap(param);

        return hwSubjectListMap;
    }

    //根据考试id获取考试大题题干信息
    @Override
    public List<Map<String,Object>> findHwMainByHwId(String studentId,String courseId,String semesterId,String hwId){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("semesterId",semesterId);
        param.put("hwId", hwId);

        List<Map<String, Object>>  hwMainListMap = hwLibraryDao.findHwMainByMap(param);

        return hwMainListMap;
    }

    @Override
    public Map<String,Object> findHwMainTestByMap(String testId){

        Map<String, Object> param = new HashMap<>();

        param.put("testId", testId);

        return hwLibraryDao.findHwMainTestByMap(param);
    }

    //根据考试id获取考试题干选项信息
    @Override
    public List<Map<String,Object>> findHwOptionByTestId(List<String> testIdList){

        Map<String, Object> param = new HashMap<>();
        param.put("list", testIdList);

        List<Map<String, Object>>  hwOptionListMap = hwLibraryDao.findHwOptionByMap(param);

        return hwOptionListMap;
    }

    //根据考试id获取考试题干答案信息
    @Override
    public List<Map<String,Object>> findHwAnswerByTestId(List<String> testIdList){

        Map<String, Object> param = new HashMap<>();
        param.put("list", testIdList);

        List<Map<String, Object>>  hwAnswerListMap = hwLibraryDao.findHwAnswerByMap(param);

        return hwAnswerListMap;
    }

    //根据考试id获取考试题干详解信息
    @Override
    public List<Map<String,Object>> findHwExplainByTestId(List<String> testIdList){

        Map<String, Object> param = new HashMap<>();
        param.put("list", testIdList);

        List<Map<String,Object>>  hwExplainListMap = hwLibraryDao.findHwExplainByMap(param);

        return hwExplainListMap;
    }

    //学生作业答题列表
    @Override
    public List<HwStudentRecord> findHwStudentRecordByMap(String studentId, String courseId, String hwId){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("hwId",hwId);

        List<HwStudentRecord> hwStudentRecordList = hwLibraryDao.findHwStudentRecordByMap(param);

        return hwStudentRecordList;
    }

    @Override
    public int findHwStudentCountByMap(String studentId, String courseId, String hwId,String testId,int correctStatus){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("hwId",hwId);
        param.put("testId",testId);
        param.put("correctStatus",correctStatus);

        int count = hwLibraryDao.findHwStudentCountByMap(param);

        return count;
    }

    @Override
    public String findHwStudentTestIdsByMap(String studentId, String courseId, String hwId,String testId,int correctStatus){

        Map<String, Object> param = new HashMap<>();
        param.put("studentId",studentId);
        param.put("courseId",courseId);
        param.put("hwId",hwId);
        param.put("testId",testId);
        param.put("correctStatus",correctStatus);
        String testids = "";
        List<Map<String,Object>>  testidList = hwLibraryDao.findHwStudentTestIdsByMap(param);
        for(Map<String,Object> testidMap : testidList){
            String testid = (String)testidMap.get("test_id");
            testids += testid+",";
        }
        return testids;
    }

    //学生答题保存
    @Override
    public int hwStudentSave(HwStudentRecord hwStudentRecord){

        hwStudentRecord.setCreateDate(new Date());
        hwStudentRecord.setUpdateDate(new Date());

        return hwLibraryDao.hwStudentSave(hwStudentRecord);
    }

    @Override
    public int hwStudentUpdate(HwStudentRecord hwStudentRecord){

        hwStudentRecord.setUpdateDate(new Date());

        return hwLibraryDao.hwStudentUpdate(hwStudentRecord);
    }

    @Override
    public int hwStudentDelete(String studentId,String courseId,String hwId,String testId){

        HwStudentRecord hwStudentRecord = new HwStudentRecord();

        hwStudentRecord.setStudentId(studentId);
        hwStudentRecord.setCourseId(courseId);
        hwStudentRecord.setHwId(hwId);
        hwStudentRecord.setTestId(testId);

        return hwLibraryDao.hwStudentDelete(hwStudentRecord);
    }

}
